﻿// -----------------------------------------------------------------------
// <copyright file="ThuocServices.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------
namespace ASS.BUS.Services
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using ASS.BUS.DTO;
    using ASS.DAO;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ThuocServices
    {
        public bool Add(Thuoc thuoc)
        {
            bool addSuccsess = false;
            using (var db = new DataContext())
            {
                try
                {
                    db.Thuocs.Add(thuoc);
                    db.SaveChanges();
                    addSuccsess = true;
                }
                catch (Exception ex)
                {
                    addSuccsess = false;
                    MessageBox.Show(ex.Message);
                }
            }
            return addSuccsess;
        }

        public Thuoc GetThuoc(string ten)
        {
            using (var db = new DataContext())
            {
                var item = db.Thuocs.Single(x => x.Ten == ten);
               
                if (item != null)
                {
                    return item;
                }
                else
                {
                    return null;
                }
            }
        }

        public List<Thuoc> GetThuocs()
        {
            using (var db = new DataContext())
            {
                var items = db.Thuocs.ToList();

                return items;
            }
        }
    }
}
